<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
        <todo>
            <todo-title slot="todo-title" v-bind:title="title"></todo-title>
            <todo-items slot="todo-items" v-for="(item,index) in todoItems" v-bind:xpp="item"
             :index="index" v-on:remove="removeItems(index)" key="index"
            ></todo-items><!--remove 为自定义属性-->
        </todo>
</div>
<!--导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.min.js"></script>
<script>
    Vue.component("todo",{
        template: '<div>' +
            '<slot name="todo-title">' +
            '</slot>' +
            '<ul>' +
            '<slot name="todo-items">' +
            '</slot>' +
            '</ul>' +
            '</div>'
    });
    Vue.component("todo-title",{
        props: ['title'],
        template: '<div>{{title}}</div>'
    });
    Vue.component("todo-items",{
        props: ['xpp','index'],
        template:'<li>{{xpp}}--{{index}}<button @click="remove">删除</button></li>',
        methods:{
            remove:function (index){
                this.$emit('remove',index);//自定义的事件分发，可以调用自定义的事件
            }
        }
    });
    var vm=new Vue({
        el: "#app",
        data: {
            title: "爸爸妈妈去上班",
            todoItems: ["我去幼儿园","幼儿园里去打架","输了了就回家"]
        },
        methods: {
            removeItems: function (index){
                console.log("删除了"+this.todoItems[index]+"ok")
                this.todoItems.splice(index,1);//一次删除一个元素
            }
        }
    });
</script>
</body>
</html>